/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * jifRegistrarPrecioRequerrimientos.java
 *
 * Created on 30-sep-2010, 12:36:37
 */

package Requerrimientos;

import administracion.delegate.GestionPedidosDelegate;
import administracion.helper.Listas;
import administracion.helper.Utiles_MensajesDialogo;
import administracion.helper.Utiles_Tabla;
import com.jidesoft.hints.ListDataIntelliHints;
import java.awt.event.KeyEvent;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jdesktop.beansbinding.AbstractBindingListener;
import org.jdesktop.beansbinding.AutoBinding;
import org.jdesktop.beansbinding.BindingGroup;
import org.jdesktop.beansbinding.ELProperty;
import org.jdesktop.swingbinding.JTableBinding;
import org.jdesktop.swingbinding.SwingBindings;
import suministros.ejb30.TO.CentroCostoTO;
import suministros.ejb30.TO.EmpresaTO;
import suministros.ejb30.TO.SuministroTO;
import suministros.ejb30.TO.UnidadOrganizativaTO;
import suministros.ejb30.TO.ZonaTO;
import suministros.ejb30.entity.CentroCosto;
import suministros.ejb30.entity.Parametros;
import suministros.ejb30.entity.UnidadOrganizativa;
import suministros.ejb30.helper.Utiles_Convertir;
import org.jdesktop.beansbinding.AbstractBindingListener;
import org.jdesktop.beansbinding.AutoBinding;
import org.jdesktop.beansbinding.Binding;
import org.jdesktop.beansbinding.BindingGroup;
import org.jdesktop.beansbinding.ELProperty;
import org.jdesktop.swingbinding.JTableBinding;
import org.jdesktop.swingbinding.SwingBindings;

/**
 *
 * @author Diana
 */
public class jifRegistrarPrecioRequerrimientos extends javax.swing.JInternalFrame {
    List<EmpresaTO> empresas;
    List<SuministroTO> listasuministros=new ArrayList<SuministroTO>();
    private JTableBinding jTableBinding;
    int paginas=0;
    int paginaActual=0;
    boolean estado= false;
    List<ZonaTO> zonas;
    List<SuministroTO> listasuministros1=new ArrayList<SuministroTO>();
    private JTableBinding jTableBinding1;
    int paginas1=0;
    int paginaActual1=0;
    boolean estado1= false;
    private UnidadOrganizativa unid_org_pedido;
    private CentroCosto centro_costos_pedido;
    private ListDataIntelliHints intelliHintsUnidOrganica;
    private ListDataIntelliHints intelliHintsCentroCostos;
    List<SuministroTO> listadetalles1;

    /** Creates new form jifRegistrarPrecioRequerrimientos */
    public jifRegistrarPrecioRequerrimientos() {
        /*try {
            if (GestionPedidosDelegate.getInstance().verificarFechasAprobarRequerrimientos()) {
                initComponents();
                empresas = Listas.getEmpresas();
                if(empresas.isEmpty()){
                    this.jCheckBox1.setEnabled(false);
                }
                this.jbAceptar.setVisible(true);
                this.jCheckBox1.setSelected(false);
                this.llenarComboEmpresa();
                this.llenarComboZonas();
                this.jcbEmpresa.setEnabled(false);
                this.jbtAnterior.setEnabled(false);
                this.jbtAnteriort.setEnabled(false);
                this.jbtSiguiente.setEnabled(false);
                this.jbtSiguientet.setEnabled(false);
            } else {
                Utiles_MensajesDialogo.mensajeAlerta("No ha llegado la fecha para evaluar los requerrimientos");
            }
        } catch (Exception ex) {
             Utiles_MensajesDialogo.mensajeAlerta("No se ha podido establecer la conexion con el servidor");
        }*/
         initComponents();
                empresas = Listas.getEmpresas();
                if(empresas.isEmpty()){
                    this.jCheckBox1.setEnabled(false);
                }
                listadetalles1=new ArrayList<SuministroTO>();
                this.jbAceptar.setVisible(true);
                this.jCheckBox1.setSelected(false);
                this.llenarComboEmpresa();
                this.llenarComboZonas();
                this.jcbEmpresa.setEnabled(false);
                this.jbtAnterior.setEnabled(false);
                this.jbtAnteriort.setEnabled(false);
                this.jbtSiguiente.setEnabled(false);
                this.jbtSiguientet.setEnabled(false);
                this.jbtAnterior1.setEnabled(false);
                this.jbtAnteriort1.setEnabled(false);
                this.jbtSiguiente1.setEnabled(false);
                this.jbtSiguientet1.setEnabled(false);
                
                cargaHintsIndependientes();
    }
     private void cargaHintsIndependientes() {
        this.intelliHintsUnidOrganica = new ListDataIntelliHints(this.jtfDesUnOrganica, Listas.getUn_organizativa());
      }
     public void limpiar(){
         this.listasuministros.clear();
         this.listasuministros1.clear();
         this.listadetalles1.clear();
         this.jtfCodCenCostos.setText("");
         this.jtfCodUnorganica.setText("");
         this.jtfDesUnOrganica.setText("");
         this.jtfDescCenCostos.setText("");
         this.actualizarTabla();
         this.actualizarTabla1();
     }
    private void llenarComboZonas() {
        zonas = null;
        List listaPaises_cbo = this.cboBeanBindingZona1.getLista();
        listaPaises_cbo.clear();
        try
        {
          zonas = Listas.getZonas();
          this.cboBeanBindingZona1.setLista(zonas);
          this.bindingGroup.bind();
          this.jcbZona.updateUI();
          this.jcbZona.setSelectedIndex(0);
        } catch (Exception ex) {
          Utiles_MensajesDialogo.mensajeAlerta("Error al obtener zonas\n" + ex.getMessage());
          ex.printStackTrace();
          Logger.getLogger(jifRegistrarPrecioRequerrimientos.class.getName()).log(Level.SEVERE, null, ex);
        }
      }
      private void llenarComboEmpresa() {
        empresas = null;
        List listaPaises_cbo = this.cboBeanBindingEmpresa1.getLista();
        listaPaises_cbo.clear();
        try
        {
           if(this.jCheckBox1.isSelected()){
                empresas = Listas.getEmpresas();
            }
            else{
                empresas = Listas.getEmpresaPrincipal();
            }
          this.cboBeanBindingEmpresa1.setLista(empresas);
          this.bindingGroup.bind();
          this.jcbEmpresa.updateUI();
          this.jcbEmpresa.setSelectedIndex(0);
        } catch (Exception ex) {
          Utiles_MensajesDialogo.mensajeAlerta("Error al obtener empresas\n" + ex.getMessage());
          ex.printStackTrace();
          Logger.getLogger(jifEvaluarRequerimiento.class.getName()).log(Level.SEVERE, null, ex);
        }
      }
       public void actualizarTabla(){
        List<SuministroTO> listadetalles= this.recorrerTabla();
        this.bindingGroup = new BindingGroup();

        this.jTableBinding = SwingBindings.createJTableBinding(AutoBinding.UpdateStrategy.READ_WRITE, listadetalles, this.jTable1);
        JTableBinding.ColumnBinding columnBinding0 = this.jTableBinding.addColumnBinding(ELProperty.create("${id_suministro}"));

        columnBinding0.setColumnName("ID SUMINISTRO");
        columnBinding0.setColumnClass(String.class);
        columnBinding0.setEditable(false);

        JTableBinding.ColumnBinding columnBinding1 = this.jTableBinding.addColumnBinding(ELProperty.create("${descripcion}"));

        columnBinding1.setColumnName("DESCRIPCION");
        columnBinding1.setColumnClass(String.class);
        columnBinding1.setEditable(false);

        JTableBinding.ColumnBinding columnBinding2 = this.jTableBinding.addColumnBinding(ELProperty.create("${unidad_medida}"));

        columnBinding2.setColumnName("UN.MEDIDA");
        columnBinding2.setColumnClass(String.class);
        columnBinding2.setEditable(false);

        JTableBinding.ColumnBinding columnBinding3 = this.jTableBinding.addColumnBinding(ELProperty.create("${precioPromedio}"));

        columnBinding3.setColumnName("PREC.PROM.");
        columnBinding3.setColumnClass(BigDecimal.class);
        columnBinding3.setEditable(false);

        JTableBinding.ColumnBinding columnBinding4 = this.jTableBinding.addColumnBinding(ELProperty.create("${precioActual}"));

        columnBinding4.setColumnName("PREC.ACTUAL");
        columnBinding4.setColumnClass(BigDecimal.class);
        columnBinding4.setEditable(true);



        this.bindingGroup.addBinding(this.jTableBinding);
        this.bindingGroup.bind();

        int[] porcentajes= {15,51,10,12,12};
        try {
            Utiles_Tabla.definirAnchoColumnasJTable(this.jTable1, porcentajes);
        } catch (Exception ex) {
            Logger.getLogger(jifRegistrarPrecioRequerrimientos.class.getName()).log(Level.SEVERE, null, ex);
        }
     }

       public void actualizarTabla1(){
       listadetalles1= this.recorrerTabla1();
        this.bindingGroup = new BindingGroup();
        this.bindingGroup.addBindingListener(new AbstractBindingListener() {
                       @Override public void synced(Binding binding) {
                        try{
                            if(!listadetalles1.isEmpty()){
                                int selec=jTable2.getSelectedRow();
                                if(selec>=0){
                                SuministroTO detaord_aux= listadetalles1.get(jTable2.convertRowIndexToModel(selec));
                                detaord_aux.setValorTotal(detaord_aux.getStock().multiply(detaord_aux.getPrecioActual()).setScale(2,RoundingMode.HALF_UP));
                                actualizarTabla1();
                                }


                            }

                    }catch(ArrayIndexOutOfBoundsException ex){
                    }
                        catch(Exception e){
                        e.printStackTrace();
                    }

                }
            });
        this.jTableBinding1 = SwingBindings.createJTableBinding(AutoBinding.UpdateStrategy.READ_WRITE, listadetalles1, this.jTable2);
        JTableBinding.ColumnBinding columnBinding0 = this.jTableBinding1.addColumnBinding(ELProperty.create("${id_suministro}"));

        columnBinding0.setColumnName("ID SUMINISTRO");
        columnBinding0.setColumnClass(String.class);
        columnBinding0.setEditable(false);

        JTableBinding.ColumnBinding columnBinding1 = this.jTableBinding1.addColumnBinding(ELProperty.create("${descripcion}"));

        columnBinding1.setColumnName("DESCRIPCION");
        columnBinding1.setColumnClass(String.class);
        columnBinding1.setEditable(false);

        JTableBinding.ColumnBinding columnBinding2 = this.jTableBinding1.addColumnBinding(ELProperty.create("${unidad_medida}"));

        columnBinding2.setColumnName("UN.MEDIDA");
        columnBinding2.setColumnClass(String.class);
        columnBinding2.setEditable(false);

        JTableBinding.ColumnBinding columnBinding3 = this.jTableBinding1.addColumnBinding(ELProperty.create("${stock}"));

        columnBinding3.setColumnName("CANTIDAD");
        columnBinding3.setColumnClass(BigDecimal.class);
        columnBinding3.setEditable(false);


        JTableBinding.ColumnBinding columnBinding4 = this.jTableBinding1.addColumnBinding(ELProperty.create("${precioPromedio}"));

        columnBinding4.setColumnName("PREC.PROM.");
        columnBinding4.setColumnClass(BigDecimal.class);
        columnBinding4.setEditable(false);



        JTableBinding.ColumnBinding columnBinding5 = this.jTableBinding1.addColumnBinding(ELProperty.create("${precioActual}"));

        columnBinding5.setColumnName("PREC.ACTUAL");
        columnBinding5.setColumnClass(BigDecimal.class);
        columnBinding5.setEditable(true);

        JTableBinding.ColumnBinding columnBinding6 = this.jTableBinding1.addColumnBinding(ELProperty.create("${valorTotal}"));

        columnBinding6.setColumnName("MONTO TOTAL");
        columnBinding6.setColumnClass(BigDecimal.class);
        columnBinding6.setEditable(true);




        this.bindingGroup.addBinding(this.jTableBinding1);
        this.bindingGroup.bind();

        int[] porcentajes= {18,40,10,8,8,8,8};
        try {
            Utiles_Tabla.definirAnchoColumnasJTable(this.jTable2, porcentajes);
        } catch (Exception ex) {
            Logger.getLogger(jifRegistrarPrecioRequerrimientos.class.getName()).log(Level.SEVERE, null, ex);
        }
     }

     public void llenarSuministros(){
    

        try {
            this.listasuministros= new ArrayList<SuministroTO>();
            this.listasuministros.clear();
            String empresa=((EmpresaTO)this.jcbEmpresa.getSelectedItem()).getCodigo();
            String zona= ((ZonaTO)this.jcbZona.getSelectedItem()).getId_zona();
            this.listasuministros = GestionPedidosDelegate.getInstance().getDatosSuministroEmpresaRequeridos(empresa, zona);
            this.paginas=(int)Math.ceil(listasuministros.size()/5);
            if(listasuministros.isEmpty()){
                 Utiles_MensajesDialogo.mensajeAlerta("No se han encontrado suministros requeridos");
            }
            else{
                this.jbAceptar.setEnabled(true);
            }
            this.actualizarTabla();


        } catch (Exception ex) {
            Logger.getLogger(jifRegistrarPrecioRequerrimientos.class.getName()).log(Level.SEVERE, null, ex);
        }

     }
      public void llenarSuministros1(){


        try {
            this.listasuministros1= new ArrayList<SuministroTO>();
            this.listasuministros1.clear();
            String empresa=((EmpresaTO)this.jcbEmpresa.getSelectedItem()).getCodigo();
            String zona= ((ZonaTO)this.jcbZona.getSelectedItem()).getId_zona();
            this.listasuministros1 = GestionPedidosDelegate.getInstance().getDatosServicioEmpresaRequeridos(empresa, zona, this.jtfCodCenCostos.getText());
            this.paginas1=(int)Math.ceil(listasuministros1.size()/5);
            if(listasuministros1.isEmpty()){
                 Utiles_MensajesDialogo.mensajeAlerta("No se han encontrado servicios requeridos");
            }
            else{
            }
            this.actualizarTabla1();


        } catch (Exception ex) {
            Logger.getLogger(jifRegistrarPrecioRequerrimientos.class.getName()).log(Level.SEVERE, null, ex);
        }

     }

     public List<SuministroTO> recorrerTabla(){
          List<SuministroTO> detalles= new ArrayList<SuministroTO>();
         if(paginaActual>=(paginas)){
             int indice= this.paginaActual*5;
             for(int i=indice; i<this.listasuministros.size(); i++){
                 detalles.add(listasuministros.get(i));
             }
             return detalles;
         }else{
             int indice= this.paginaActual*5;
             for(int i=indice; i<indice+5; i++){
                 detalles.add(listasuministros.get(i));
             }
         }

         return detalles;
     }
     public List<SuministroTO> recorrerTabla1(){
          List<SuministroTO> detalles= new ArrayList<SuministroTO>();
         if(paginaActual1>=(paginas1)){
             int indice= this.paginaActual1*5;
             for(int i=indice; i<this.listasuministros1.size(); i++){
                 detalles.add(listasuministros1.get(i));
             }
             return detalles;
         }else{
             int indice= this.paginaActual1*5;
             for(int i=indice; i<indice+5; i++){
                 detalles.add(listasuministros1.get(i));
             }
         }

         return detalles;
     }
     public void ajustarPrecioPromedio(){
         for(SuministroTO sumi: this.listasuministros){
             sumi.setPrecioActual(sumi.getPrecioPromedio());
         }
         this.actualizarTabla();
         
     }
      private void buscarUnidOrganica()
  {
        List centros_hints;
        UnidadOrganizativaTO unoorg;
        if(this.jtfCodUnorganica.getText().trim().length() < 1)
        {
            unoorg = (UnidadOrganizativaTO)intelliHintsUnidOrganica.getSelectedHint();
            centros_hints = Listas.getCentro_Costos_Unid_Organica(unoorg.getCod_Uni_Organizativa().trim());
        } else
        {
            unoorg = Listas.getUn_organizativa_codigo(jtfCodUnorganica.getText().trim());
            centros_hints = Listas.getCentro_Costos_Unid_Organica(jtfCodUnorganica.getText().trim());
        }
        if(centros_hints.size() < 1)
        {
            Utiles_MensajesDialogo.mensajeError("La unidad organica no existe!");
            this.jtfDesUnOrganica.setText("");
            unid_org_pedido = null;
                try{
                    intelliHintsCentroCostos.getCompletionList().clear();
                    intelliHintsCentroCostos = null;
                }catch(NullPointerException e){

                }

        } else
        {
            unid_org_pedido = Utiles_Convertir.convertirToUnidadOrganizativa_UnidadOrganizativaTO(unoorg);
            jtfDesUnOrganica.setText(unoorg.toString());
            jtfCodUnorganica.setText(unoorg.getCod_Uni_Organizativa());
            if(intelliHintsCentroCostos != null)
            {
                intelliHintsCentroCostos.getCompletionList().clear();
                intelliHintsCentroCostos = null;
                jtfCodCenCostos.setText("");
                this.jtfDescCenCostos.setText("");
            }
            intelliHintsCentroCostos = new ListDataIntelliHints(jtfDescCenCostos, centros_hints);
            jtfCodCenCostos.requestFocus();
        }
  }

   private void buscarCentroCostos()
  {
    CentroCostoTO centro_cost;
    if (this.jtfCodCenCostos.getText().trim().length() < 1) {

      try { centro_cost = (CentroCostoTO)this.intelliHintsCentroCostos.getSelectedHint();
      } catch (NullPointerException ex) {
        centro_cost = null;
      }
    } else {
      centro_cost = Listas.getCentro_Costos_codigo(this.jtfCodCenCostos.getText().trim());
    }

    if (centro_cost == null) {
      Utiles_MensajesDialogo.mensajeError("El centro de costos no existe!");
      this.jtfDescCenCostos.setText("");
      this.centro_costos_pedido = null;
    } else {
      this.jtfDescCenCostos.setText(centro_cost.toString());
      this.jtfCodCenCostos.setText(centro_cost.getCod_CentroCosto());
      this.centro_costos_pedido = Utiles_Convertir.convertirToCentroCosto_CentroCostoTO(centro_cost);
      this.llenarSuministros1();
    }
  }


     public void guardarPrecio(){
        try {
            GestionPedidosDelegate.getInstance().guardarPrecioRequerrimientos(listasuministros);
            GestionPedidosDelegate.getInstance().guardarPrecioRequerrimientosServicio(listasuministros1, this.jtfCodCenCostos.getText());
            Utiles_MensajesDialogo.mensajeExito();
        } catch (Exception ex) {
           Utiles_MensajesDialogo.mensajeError("No se pudo realizar la transaccion");
        }
     }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        jLabel1 = new javax.swing.JLabel();
        cboBeanBindingEmpresa1 = new administracion.BeanBinding.CboBeanBindingEmpresa();
        cboBeanBindingZona1 = new administracion.BeanBinding.CboBeanBindingZona();
        jcbEmpresa = new javax.swing.JComboBox();
        jCheckBox1 = new javax.swing.JCheckBox();
        jPanel1 = new javax.swing.JPanel();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jLabel3 = new javax.swing.JLabel();
        jblPaginaActual = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jblTotal = new javax.swing.JLabel();
        jbtAnteriort = new javax.swing.JButton();
        jbtAnterior = new javax.swing.JButton();
        jbtSiguiente = new javax.swing.JButton();
        jbtSiguientet = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTable2 = new javax.swing.JTable();
        jLabel5 = new javax.swing.JLabel();
        jblPaginaActual1 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jblTotal1 = new javax.swing.JLabel();
        jbtAnteriort1 = new javax.swing.JButton();
        jbtAnterior1 = new javax.swing.JButton();
        jbtSiguiente1 = new javax.swing.JButton();
        jbtSiguientet1 = new javax.swing.JButton();
        jLabel7 = new javax.swing.JLabel();
        jtfCodUnorganica = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jtfDesUnOrganica = new javax.swing.JTextField();
        jtfDescCenCostos = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jtfCodCenCostos = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jbtGenerar = new javax.swing.JButton();
        jLabel14 = new javax.swing.JLabel();
        jcbZona = new javax.swing.JComboBox();
        jbAceptar = new javax.swing.JButton();
        jbCancelar = new javax.swing.JButton();

        jLabel1.setText("jLabel1");

        setTitle("REGISTRAR PRECIO REQUERRIMIENTOS");

        org.jdesktop.beansbinding.ELProperty eLProperty = org.jdesktop.beansbinding.ELProperty.create("${lista}");
        org.jdesktop.swingbinding.JComboBoxBinding jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, cboBeanBindingEmpresa1, eLProperty, jcbEmpresa);
        bindingGroup.addBinding(jComboBoxBinding);

        jcbEmpresa.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jcbEmpresaKeyPressed(evt);
            }
        });

        jCheckBox1.setFont(new java.awt.Font("Arial", 1, 12));
        jCheckBox1.setText("POR ENCARGO");
        jCheckBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox1ActionPerformed(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "DETALLE DE SUMINISTRO REQUERIDOS", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11), new java.awt.Color(0, 0, 255))); // NOI18N

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Codigo", "Descripcion", "Unidad", "Precio Promedio", "Precio Actual"
            }
        ));
        jScrollPane1.setViewportView(jTable1);

        jLabel3.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel3.setText("PAGINA:");

        jblPaginaActual.setFont(new java.awt.Font("Arial", 1, 12));
        jblPaginaActual.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jblPaginaActual.setText("0");

        jLabel4.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel4.setText("/");

        jblTotal.setFont(new java.awt.Font("Arial", 1, 12));
        jblTotal.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jblTotal.setText("0");

        jbtAnteriort.setIcon(new javax.swing.ImageIcon("D:\\Sistema\\Librerias\\2leftarrow.png")); // NOI18N
        jbtAnteriort.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtAnteriortActionPerformed(evt);
            }
        });

        jbtAnterior.setIcon(new javax.swing.ImageIcon("D:\\Sistema\\Librerias\\1leftarrow.png")); // NOI18N
        jbtAnterior.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtAnteriorActionPerformed(evt);
            }
        });

        jbtSiguiente.setIcon(new javax.swing.ImageIcon("D:\\Sistema\\Librerias\\1rightarrow.png")); // NOI18N
        jbtSiguiente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtSiguienteActionPerformed(evt);
            }
        });

        jbtSiguientet.setIcon(new javax.swing.ImageIcon("D:\\Sistema\\Librerias\\2rightarrow.png")); // NOI18N
        jbtSiguientet.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtSiguientetActionPerformed(evt);
            }
        });

        jButton1.setFont(new java.awt.Font("Arial", 1, 12));
        jButton1.setMnemonic('A');
        jButton1.setText("Ajustar al Precio Promedio");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(109, 109, 109)
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jblPaginaActual, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 12, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jblTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(29, 29, 29)
                        .addComponent(jbtAnteriort)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jbtAnterior)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jbtSiguiente)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jbtSiguientet))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(445, 445, 445)
                        .addComponent(jButton1))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 620, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(18, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addComponent(jButton1)
                .addGap(5, 5, 5)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 258, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jbtAnterior)
                        .addComponent(jbtSiguiente)
                        .addComponent(jbtAnteriort, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jbtSiguientet, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel3)
                        .addComponent(jblPaginaActual, javax.swing.GroupLayout.DEFAULT_SIZE, 17, Short.MAX_VALUE)
                        .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jblTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        jTabbedPane1.addTab("EXISTENCIAS Y ACTIVOS", jPanel2);

        jTable2.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "CODIGO", "DESCRIPCION", "UNIDAD", "CANTIDAD", "PRECIO", "MONTO"
            }
        ));
        jScrollPane2.setViewportView(jTable2);

        jLabel5.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel5.setText("PAGINA:");

        jblPaginaActual1.setFont(new java.awt.Font("Arial", 1, 12));
        jblPaginaActual1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jblPaginaActual1.setText("0");

        jLabel6.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel6.setText("/");

        jblTotal1.setFont(new java.awt.Font("Arial", 1, 12));
        jblTotal1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jblTotal1.setText("0");

        jbtAnteriort1.setIcon(new javax.swing.ImageIcon("D:\\Sistema\\Librerias\\2leftarrow.png")); // NOI18N
        jbtAnteriort1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtAnteriort1ActionPerformed(evt);
            }
        });

        jbtAnterior1.setIcon(new javax.swing.ImageIcon("D:\\Sistema\\Librerias\\1leftarrow.png")); // NOI18N
        jbtAnterior1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtAnterior1ActionPerformed(evt);
            }
        });

        jbtSiguiente1.setIcon(new javax.swing.ImageIcon("D:\\Sistema\\Librerias\\1rightarrow.png")); // NOI18N
        jbtSiguiente1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtSiguiente1ActionPerformed(evt);
            }
        });

        jbtSiguientet1.setIcon(new javax.swing.ImageIcon("D:\\Sistema\\Librerias\\2rightarrow.png")); // NOI18N
        jbtSiguientet1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtSiguientet1ActionPerformed(evt);
            }
        });

        jLabel7.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel7.setText("COD.UN.ORGAN.");

        jtfCodUnorganica.setToolTipText("Codigo de la unidad organica");
        jtfCodUnorganica.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtfCodUnorganicaActionPerformed(evt);
            }
        });

        jLabel8.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel8.setText("DESC.UN.ORGAN.");

        jtfDesUnOrganica.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtfDesUnOrganicaActionPerformed(evt);
            }
        });
        jtfDesUnOrganica.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jtfDesUnOrganicaKeyPressed(evt);
            }
        });

        jtfDescCenCostos.setFont(new java.awt.Font("Arial 12 Simple", 0, 12));
        jtfDescCenCostos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtfDescCenCostosActionPerformed(evt);
            }
        });
        jtfDescCenCostos.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jtfDescCenCostosKeyPressed(evt);
            }
        });

        jLabel9.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel9.setText("DESC.CEN.COSTOS");

        jtfCodCenCostos.setFont(new java.awt.Font("Arial 12 Simple", 0, 12));
        jtfCodCenCostos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtfCodCenCostosActionPerformed(evt);
            }
        });

        jLabel10.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel10.setText("COD.CEN.COSTOS");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(107, 107, 107)
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jblPaginaActual1, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 12, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jblTotal1, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(30, 30, 30)
                        .addComponent(jbtAnteriort1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jbtAnterior1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jbtSiguiente1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jbtSiguientet1))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 630, Short.MAX_VALUE)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel3Layout.createSequentialGroup()
                                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel7)
                                    .addComponent(jLabel10))
                                .addGap(14, 14, 14)
                                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jtfCodUnorganica, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jtfCodCenCostos, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(18, 18, 18)
                                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel8)
                                    .addComponent(jLabel9))
                                .addGap(18, 18, 18)
                                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jtfDescCenCostos)
                                    .addComponent(jtfDesUnOrganica, javax.swing.GroupLayout.DEFAULT_SIZE, 275, Short.MAX_VALUE))))))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(jtfCodUnorganica, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8)
                    .addComponent(jtfDesUnOrganica, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(jLabel9)
                    .addComponent(jtfCodCenCostos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtfDescCenCostos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 228, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jbtAnterior1)
                        .addComponent(jbtSiguiente1)
                        .addComponent(jbtAnteriort1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jbtSiguientet1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel5)
                        .addComponent(jblPaginaActual1, javax.swing.GroupLayout.DEFAULT_SIZE, 17, Short.MAX_VALUE)
                        .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jblTotal1, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        jTabbedPane1.addTab("SERVICIOS", jPanel3);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 653, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 361, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.getAccessibleContext().setAccessibleName("EXISTENCIAS Y ACTIVOS");

        jbtGenerar.setFont(new java.awt.Font("Arial", 1, 12));
        jbtGenerar.setMnemonic('G');
        jbtGenerar.setText("GENERAR");
        jbtGenerar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtGenerarActionPerformed(evt);
            }
        });

        jLabel14.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel14.setText("ZONA:");

        jcbZona.setFont(new java.awt.Font("Arial", 0, 12));

        eLProperty = org.jdesktop.beansbinding.ELProperty.create("${lista}");
        jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, cboBeanBindingZona1, eLProperty, jcbZona);
        bindingGroup.addBinding(jComboBoxBinding);

        jcbZona.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jcbZonaItemStateChanged(evt);
            }
        });
        jcbZona.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcbZonaActionPerformed(evt);
            }
        });
        jcbZona.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jcbZonaKeyPressed(evt);
            }
        });

        jbAceptar.setFont(new java.awt.Font("Arial", 0, 12));
        jbAceptar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconoscomb/16x16ozygen/actions/button_ok.png"))); // NOI18N
        jbAceptar.setMnemonic('A');
        jbAceptar.setText("ACEPTAR");
        jbAceptar.setEnabled(false);
        jbAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbAceptarActionPerformed(evt);
            }
        });

        jbCancelar.setFont(new java.awt.Font("Arial", 0, 12));
        jbCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconoscomb/16x16ozygen/actions/button_cancel.png"))); // NOI18N
        jbCancelar.setMnemonic('C');
        jbCancelar.setText("CANCELAR");
        jbCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbCancelarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jbtGenerar)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jCheckBox1)
                        .addGap(13, 13, 13)
                        .addComponent(jcbEmpresa, javax.swing.GroupLayout.PREFERRED_SIZE, 209, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(44, 44, 44)
                        .addComponent(jLabel14)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jcbZona, javax.swing.GroupLayout.PREFERRED_SIZE, 214, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
            .addGroup(layout.createSequentialGroup()
                .addGap(218, 218, 218)
                .addComponent(jbAceptar, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbCancelar))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(19, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jcbEmpresa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jCheckBox1)
                    .addComponent(jLabel14)
                    .addComponent(jcbZona, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbtGenerar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(13, 13, 13)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbAceptar)
                    .addComponent(jbCancelar)))
        );

        bindingGroup.bind();

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jcbEmpresaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jcbEmpresaKeyPressed
        if (evt.getKeyCode() == KeyEvent.VK_ENTER ){
            if(this.jcbEmpresa.getSelectedIndex()>=0){
                this.jbtGenerar.requestFocus();
            }
        }
}//GEN-LAST:event_jcbEmpresaKeyPressed

    private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox1ActionPerformed
        if(this.jCheckBox1.isSelected()){
            this.jcbEmpresa.setEnabled(true);
        } else{
            this.jcbEmpresa.setEnabled(false);
        }
        this.llenarComboEmpresa();
       
}//GEN-LAST:event_jCheckBox1ActionPerformed

    private void jbAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbAceptarActionPerformed
        int res = javax.swing.JOptionPane.showConfirmDialog( this,"¿Esta seguro que desea realizar la transaccion?",
                "Confirmar",javax.swing.JOptionPane.YES_NO_OPTION );
        if(res==javax.swing.JOptionPane.YES_OPTION){
              this.guardarPrecio();
        }
        
}//GEN-LAST:event_jbAceptarActionPerformed

    private void jbCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbCancelarActionPerformed

        int res = javax.swing.JOptionPane.showConfirmDialog( this,"Esta seguro de salir?",
                "Confirmar",javax.swing.JOptionPane.YES_NO_OPTION );
        if(res==javax.swing.JOptionPane.YES_OPTION){

            this.dispose();

        }
}//GEN-LAST:event_jbCancelarActionPerformed

    private void jbtAnteriortActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtAnteriortActionPerformed

        try {
            estado=false;
            this.paginaActual=0;
            this.actualizarTabla();
        } catch (Exception ex) {
            Logger.getLogger(jifRegistrarPrecioRequerrimientos.class.getName()).log(Level.SEVERE, null, ex);
        }
        this.jbtAnterior.setEnabled(false);
        this.jbtAnteriort.setEnabled(false);
        this.jbtSiguiente.setEnabled(true);
        this.jbtSiguientet.setEnabled(true);
        this.jblPaginaActual.setText(this.paginaActual+1+"");
}//GEN-LAST:event_jbtAnteriortActionPerformed

    private void jbtAnteriorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtAnteriorActionPerformed

        try {
            estado=false;       
            this.paginaActual--;
            this.actualizarTabla();
            if(this.paginaActual==0){
                this.jbtAnterior.setEnabled(false);
                this.jbtAnteriort.setEnabled(false);
            }
        } catch (Exception ex) {
            Logger.getLogger(jifRegistrarPrecioRequerrimientos.class.getName()).log(Level.SEVERE, null, ex);
        }
        this.jbtSiguiente.setEnabled(true);
        this.jbtSiguientet.setEnabled(true);
        this.jblPaginaActual.setText(this.paginaActual+1+"");
}//GEN-LAST:event_jbtAnteriorActionPerformed

    private void jbtSiguienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtSiguienteActionPerformed

        try {
            estado=false;
            this.paginaActual++;
            this.actualizarTabla();
            if(this.paginaActual==this.paginas){
                this.jbtSiguiente.setEnabled(false);
                this.jbtSiguientet.setEnabled(false);
            }

        } catch (Exception ex) {
            Logger.getLogger(jifRegistrarPrecioRequerrimientos.class.getName()).log(Level.SEVERE, null, ex);
        }
        this.jbtAnterior.setEnabled(true);
        this.jbtAnteriort.setEnabled(true);
        this.jblPaginaActual.setText(this.paginaActual+1+"");
}//GEN-LAST:event_jbtSiguienteActionPerformed

    private void jbtSiguientetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtSiguientetActionPerformed

        try {
            estado=false;
            this.paginaActual=paginas;
            this.actualizarTabla();
        } catch (Exception ex) {
            Logger.getLogger(jifRegistrarPrecioRequerrimientos.class.getName()).log(Level.SEVERE, null, ex);
        }
        this.jbtAnterior.setEnabled(true);
        this.jbtAnteriort.setEnabled(true);
        this.jbtSiguiente.setEnabled(false);
        this.jbtSiguientet.setEnabled(false);
        this.jblPaginaActual.setText(this.paginaActual+1+"");
    }//GEN-LAST:event_jbtSiguientetActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
            this.ajustarPrecioPromedio();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jcbZonaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbZonaActionPerformed

}//GEN-LAST:event_jcbZonaActionPerformed

    private void jcbZonaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jcbZonaKeyPressed
        if (evt.getKeyCode() == KeyEvent.VK_ENTER ){
             this.jbtGenerar.requestFocus();
        }
}//GEN-LAST:event_jcbZonaKeyPressed

    private void jbtGenerarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtGenerarActionPerformed
        limpiar();
        if(this.jcbEmpresa.getSelectedIndex()>=0){
            if(this.jcbZona.getSelectedIndex()>=0){
                try {
                this.jbtSiguiente.setEnabled(true);
                this.jbtSiguientet.setEnabled(true);
                llenarSuministros();
                if(this.listasuministros.isEmpty()){
                    this.jblPaginaActual.setText(this.paginaActual+"");
                    this.jblTotal.setText(this.paginas+"");
                } else{
                    this.jblPaginaActual.setText(this.paginaActual+1+"");
                    this.jblTotal.setText(this.paginas+1+"");
                }

                } catch (Exception ex) {
                    Logger.getLogger(jifRegistrarPrecioRequerrimientos.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            else{
            Utiles_MensajesDialogo.mensajeAlerta("No ha seleccionado una zona");
        }

        } else{
            Utiles_MensajesDialogo.mensajeAlerta("No ha seleccionado una empresa");
        }
}//GEN-LAST:event_jbtGenerarActionPerformed

    private void jbtAnteriort1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtAnteriort1ActionPerformed
        try {
            estado1=false;
            this.paginaActual1=0;
            this.actualizarTabla1();
        } catch (Exception ex) {
            Logger.getLogger(jifRegistrarPrecioRequerrimientos.class.getName()).log(Level.SEVERE, null, ex);
        }
        this.jbtAnterior1.setEnabled(false);
        this.jbtAnteriort1.setEnabled(false);
        this.jbtSiguiente1.setEnabled(true);
        this.jbtSiguientet1.setEnabled(true);
        this.jblPaginaActual1.setText(this.paginaActual1+1+"");
    }//GEN-LAST:event_jbtAnteriort1ActionPerformed

    private void jbtAnterior1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtAnterior1ActionPerformed
      try {
            estado1=false;
            this.paginaActual1--;
            this.actualizarTabla1();
            if(this.paginaActual1==0){
                this.jbtAnterior1.setEnabled(false);
                this.jbtAnteriort1.setEnabled(false);
            }
        } catch (Exception ex) {
            Logger.getLogger(jifRegistrarPrecioRequerrimientos.class.getName()).log(Level.SEVERE, null, ex);
        }
        this.jbtSiguiente1.setEnabled(true);
        this.jbtSiguientet1.setEnabled(true);
        this.jblPaginaActual1.setText(this.paginaActual1+1+"");
    }//GEN-LAST:event_jbtAnterior1ActionPerformed

    private void jbtSiguiente1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtSiguiente1ActionPerformed
       try {
            estado1=false;
            this.paginaActual1++;
            this.actualizarTabla1();
            if(this.paginaActual1==this.paginas1){
                this.jbtSiguiente1.setEnabled(false);
                this.jbtSiguientet1.setEnabled(false);
            }

        } catch (Exception ex) {
            Logger.getLogger(jifRegistrarPrecioRequerrimientos.class.getName()).log(Level.SEVERE, null, ex);
        }
        this.jbtAnterior1.setEnabled(true);
        this.jbtAnteriort1.setEnabled(true);
        this.jblPaginaActual1.setText(this.paginaActual1+1+"");
    }//GEN-LAST:event_jbtSiguiente1ActionPerformed

    private void jbtSiguientet1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtSiguientet1ActionPerformed
         try {
            estado1=false;
            this.paginaActual1=paginas1;
            this.actualizarTabla1();
        } catch (Exception ex) {
            Logger.getLogger(jifRegistrarPrecioRequerrimientos.class.getName()).log(Level.SEVERE, null, ex);
        }
        this.jbtAnterior1.setEnabled(true);
        this.jbtAnteriort1.setEnabled(true);
        this.jbtSiguiente1.setEnabled(false);
        this.jbtSiguientet1.setEnabled(false);
        this.jblPaginaActual1.setText(this.paginaActual1+1+"");
    }//GEN-LAST:event_jbtSiguientet1ActionPerformed

    private void jtfCodUnorganicaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtfCodUnorganicaActionPerformed

        if (this.jtfCodUnorganica.getText().trim().length() < 1)
            this.jtfDesUnOrganica.requestFocus();
        else
            buscarUnidOrganica();
}//GEN-LAST:event_jtfCodUnorganicaActionPerformed

    private void jtfDesUnOrganicaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtfDesUnOrganicaActionPerformed

        buscarUnidOrganica();
}//GEN-LAST:event_jtfDesUnOrganicaActionPerformed

    private void jtfDesUnOrganicaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfDesUnOrganicaKeyPressed

        if (this.jtfCodUnorganica.getText().trim().length() > 0)
            this.jtfCodUnorganica.setText("");
}//GEN-LAST:event_jtfDesUnOrganicaKeyPressed

    private void jtfDescCenCostosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtfDescCenCostosActionPerformed

        buscarCentroCostos();
}//GEN-LAST:event_jtfDescCenCostosActionPerformed

    private void jtfDescCenCostosKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfDescCenCostosKeyPressed

        if (this.jtfCodCenCostos.getText().trim().length() > 0)
            this.jtfCodCenCostos.setText("");
}//GEN-LAST:event_jtfDescCenCostosKeyPressed

    private void jtfCodCenCostosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtfCodCenCostosActionPerformed

        if (this.jtfCodCenCostos.getText().trim().length() < 1)
            this.jtfDescCenCostos.requestFocus();
        else
            buscarCentroCostos();
}//GEN-LAST:event_jtfCodCenCostosActionPerformed

    private void jcbZonaItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jcbZonaItemStateChanged
        this.limpiar();
    }//GEN-LAST:event_jcbZonaItemStateChanged


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private administracion.BeanBinding.CboBeanBindingEmpresa cboBeanBindingEmpresa1;
    private administracion.BeanBinding.CboBeanBindingZona cboBeanBindingZona1;
    private javax.swing.JButton jButton1;
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTable jTable2;
    private javax.swing.JButton jbAceptar;
    private javax.swing.JButton jbCancelar;
    private javax.swing.JLabel jblPaginaActual;
    private javax.swing.JLabel jblPaginaActual1;
    private javax.swing.JLabel jblTotal;
    private javax.swing.JLabel jblTotal1;
    private javax.swing.JButton jbtAnterior;
    private javax.swing.JButton jbtAnterior1;
    private javax.swing.JButton jbtAnteriort;
    private javax.swing.JButton jbtAnteriort1;
    private javax.swing.JButton jbtGenerar;
    private javax.swing.JButton jbtSiguiente;
    private javax.swing.JButton jbtSiguiente1;
    private javax.swing.JButton jbtSiguientet;
    private javax.swing.JButton jbtSiguientet1;
    private javax.swing.JComboBox jcbEmpresa;
    private javax.swing.JComboBox jcbZona;
    private javax.swing.JTextField jtfCodCenCostos;
    private javax.swing.JTextField jtfCodUnorganica;
    private javax.swing.JTextField jtfDesUnOrganica;
    private javax.swing.JTextField jtfDescCenCostos;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables

}
